from django.db import models
from datetime import datetime
from django.utils import timezone
import uuid


# Create your models here.

class User(models.Model):
    uuid = models.UUIDField(
        primary_key=True,
        default=uuid.uuid4,
        editable=False)
    name = models.CharField(max_length=20, verbose_name='用户名')
    region = models.CharField(max_length=100, verbose_name='地区', null=True)
    ParentZone = models.CharField(max_length=50, verbose_name='大区', null=True)
    password = models.CharField(max_length=20, verbose_name='密码')
    is_expert = models.BooleanField(default=False, verbose_name='专家身份')
    status = models.IntegerField(default=1, verbose_name='身份')
    company = models.CharField(max_length=128, null=True, default='', verbose_name='公司名字')
    legal = models.CharField(max_length=64, null=True, default='', verbose_name='公司法人名字')
    is_registered = models.BooleanField(default=False, verbose_name='企业是否注册')
    phone = models.CharField(max_length=20, verbose_name='手机号', null=True)

    class Meta:
        verbose_name = "用户信息"
        db_table = 'estimation_user'


class Evaluate(models.Model):
    uuid = models.UUIDField(
        primary_key=True,
        default=uuid.uuid4,
        editable=False)
    name = models.CharField(max_length=20)
    date = models.DateTimeField(default=timezone.now, verbose_name='评估时间')
    applicants = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='申请人')
    csv_path = models.TextField()

    class Meta:
        verbose_name = "评估系统评估数据"


class Suggestion(models.Model):
    id = models.BigAutoField(primary_key=True, auto_created=True)
    message = models.CharField(max_length=512, null=True)
    applicants = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='申请人')

    class Meta:
        verbose_name = "评价"


class Post(models.Model):
    uuid = models.UUIDField(
        primary_key=True,
        default=uuid.uuid4,
        editable=False)
    message = models.CharField(max_length=512, null=True)
    eva_data = models.ForeignKey(Evaluate, on_delete=models.CASCADE, verbose_name='相关数据')

    class Meta:
        verbose_name = "帖子"


class Comment(models.Model):
    id = models.BigAutoField(primary_key=True, auto_created=True)
    post_id = models.ForeignKey(Evaluate, on_delete=models.CASCADE, verbose_name='评论贴')
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='评论人')
    message = models.CharField(max_length=512, null=True)
    date = models.DateTimeField(default=timezone.now, verbose_name='评论时间')

    class Meta:
        verbose_name = "回复"


class Admin(models.Model):
    id = models.BigAutoField(primary_key=True, auto_created=True)
    factor = models.CharField(max_length=20, verbose_name='因子')
    factor_chinese = models.CharField(max_length=64, verbose_name='因子中文名字', default='', null=True)
    value = models.FloatField(default=0.0, verbose_name='值')

    class Meta:
        verbose_name = "管理员信息"
